package leetcode20211004;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LUYAO
 * Date: 2021-10-04
 * Time: 10:40
 */
public class MaxProfit {
}


//股票最大利润
class Solution {
    public int maxProfit(int[] prices) {
        int cost = Integer.MAX_VALUE;
        int profit = 0;
        for(int price : prices){
            cost = Math.min(cost,price);
            profit = Math.max(profit,price-cost);
        }

        return profit;

    }
}
